package com.fengycx.app;


import cn.dev33.satoken.annotation.SaIgnore;
import com.fengycx.exception.GlobalException;
import com.fengycx.pojo.dto.DriverAuthenticDto;
import com.fengycx.pojo.dto.DriverPositionDto;
import com.fengycx.pojo.vo.DriverWorkbenchVo;
import com.fengycx.result.R;
import com.fengycx.service.IDriverAuthMaterialService;
import com.fengycx.service.IDriverService;
import com.fengycx.service.IDriverSettingService;
import com.fengycx.service.IDriverSummaryService;
import com.fengycx.service.impl.DriverAuthMaterialServiceImpl;
import com.fengycx.templeate.FileUploadTemplate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.io.IOException;

@Tag(name = "App司机对象",description = "App司机对象")
@RestController
@RequestMapping("/app/driver")
@Validated
public class AppDriverController {

    @Autowired
    private IDriverService driverService;
    @Autowired
    private IDriverAuthMaterialService driverAuthMaterialService;
    @Autowired
    private IDriverSummaryService driverSummaryService;
    @Autowired
    private IDriverSettingService driverSettingService;

    @Operation( summary= "司机注册",description = "司机注册接口")
    @Parameter(name = "code",description = "微信回调code",required = true)
    @PostMapping("/appRegister/{code}")
    @SaIgnore
    public R<Boolean> appRegister(@PathVariable("code") @NotBlank(message = "参数异常") String code){
        driverService.code2OpenId(code);
        return R.success();
    }

    @Operation( summary= "司机认证",description = "司机认证接口")
    @Parameter(name = "driverAuthenticDto",description = "司机认证对象",required = true)
    @PostMapping("/saveDriverAuthentic")
    public R<Boolean> saveDriverAuthentic(@RequestBody @Valid DriverAuthenticDto driverAuthenticDto){
        driverAuthMaterialService.saveDriverAuthentic(driverAuthenticDto);
        return R.success();
    }

    //获取当前司机工作台对象
    @Operation( summary= "获取当前司机工作台对象",description = "当前司机工作台对象获取接口")
    @GetMapping(value = "/getWorkbench")
    public R<DriverWorkbenchVo> getWorkbench(){
        return R.success(driverSummaryService.getWorkbench());
    }

    //司机上线接单
    @Operation( summary= "将司机setting缓存进redis",description = "将司机setting缓存进redis")
    @GetMapping(value = "/online")
    public R<Void> driverOnline(){
        driverSettingService.driverOnline();
        return R.success();
    }

    //司机停止接单
    @Operation( summary= "删除redis中司机的设置缓存",description = "删除redis中司机的设置缓存")
    @GetMapping(value = "/offline")
    public R<Void> driverOffline(){
        driverSettingService.driverOffline();
        return R.success();
    }


    //实时同步司机位置
    @Operation( summary= "实时同步司机位置进入Redis",description = "实时同步司机位置")
    @Parameter(name = "DriverPositionDto",description = "司机所在位置经纬度",required = true)
    @PostMapping(value = "/SyncDriverPosition")
    public R<Void> SyncDriverPosition(@RequestBody @Valid DriverPositionDto positionDto){
        driverSettingService.SyncDriverPosition(positionDto);
        return R.success();
    }

}
